﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace Business
{
    public class MtServiceLogRepository
    {
        /// <summary>
        /// Thêm 1 row có dữ liệu có sẵn vào Table
        /// </summary>
        public static void AddDataRow(DataTable dtSource, DataRow row, string status)
        {
            DataRow newRow = dtSource.NewRow();
            dtSource.Rows.Add(newRow);
            newRow["mt_service_log_id"] = row["mt_queue_id"];
            newRow["subs"] = row["subs"];
            newRow["dest_addr"] = row["dest_addr"];
            newRow["msg"] = row["msg"];
            newRow["vasp_num"] = row["vasp_num"];
            newRow["cdr_indicator"] = row["cdr_indicator"];
            newRow["date_time"] = row["date_time"];
            newRow["operator_id"] = row["operator_id"];
            newRow["gateway_id"] = row["gateway_id"];
            newRow["advertisment_id"] = row["advertisment_id"];
            newRow["collection_id"] = row["collection_id"];
            newRow["status"] = status;
        }

        public static DataTable CreateTableSchema()
        {
            return Utils.ObjectClass.CreateTableSchema<mt_service_log>();
        }

        public static void Insert(DataTable dtSouce, SqlCommand cmd)
        {
            using (SqlBulkCopy bc = new SqlBulkCopy(cmd.Connection))
            {
                bc.BulkCopyTimeout = 0;
                bc.DestinationTableName = "dbo.mt_service_log";
                bc.WriteToServer(dtSouce);
            }
        }
    }
}
